package com.ruoyi.purchase.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.purchase.domain.PurchaseExecute;
import com.ruoyi.purchase.service.IPurchaseExecuteService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购执行记录Controller
 * 
 * @author ruoyi
 * @date 2025-06-17
 */
@Controller
@RequestMapping("/purchase/execute")
public class PurchaseExecuteController extends BaseController
{
    private String prefix = "purchase/execute";

    @Autowired
    private IPurchaseExecuteService purchaseExecuteService;

    @RequiresPermissions("purchase:execute:view")
    @GetMapping()
    public String execute()
    {
        return prefix + "/execute";
    }

    /**
     * 查询采购执行记录列表
     */
    @RequiresPermissions("purchase:execute:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PurchaseExecute purchaseExecute)
    {
        startPage();
        List<PurchaseExecute> list = purchaseExecuteService.selectPurchaseExecuteList(purchaseExecute);
        return getDataTable(list);
    }

    /**
     * 导出采购执行记录列表
     */
    @RequiresPermissions("purchase:execute:export")
    @Log(title = "采购执行记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PurchaseExecute purchaseExecute)
    {
        List<PurchaseExecute> list = purchaseExecuteService.selectPurchaseExecuteList(purchaseExecute);
        ExcelUtil<PurchaseExecute> util = new ExcelUtil<PurchaseExecute>(PurchaseExecute.class);
        return util.exportExcel(list, "采购执行记录数据");
    }

    /**
     * 新增采购执行记录
     */
    @RequiresPermissions("purchase:execute:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存采购执行记录
     */
    @RequiresPermissions("purchase:execute:add")
    @Log(title = "采购执行记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PurchaseExecute purchaseExecute)
    {
        return toAjax(purchaseExecuteService.insertPurchaseExecute(purchaseExecute));
    }

    /**
     * 修改采购执行记录
     */
    @RequiresPermissions("purchase:execute:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PurchaseExecute purchaseExecute = purchaseExecuteService.selectPurchaseExecuteById(id);
        mmap.put("purchaseExecute", purchaseExecute);
        return prefix + "/edit";
    }

    /**
     * 修改保存采购执行记录
     */
    @RequiresPermissions("purchase:execute:edit")
    @Log(title = "采购执行记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PurchaseExecute purchaseExecute)
    {
        return toAjax(purchaseExecuteService.updatePurchaseExecute(purchaseExecute));
    }

    /**
     * 删除采购执行记录
     */
    @RequiresPermissions("purchase:execute:remove")
    @Log(title = "采购执行记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(purchaseExecuteService.deletePurchaseExecuteByIds(ids));
    }
}
